# adjust cwd and sys.path
def adjust_to_correct_appdir():
    import os, sys
    try:
        appdir = __file__
        print appdir
        if not appdir:
            raise ValueError
        appdir = os.path.abspath(os.path.dirname(__file__))
        os.chdir(appdir)
        sys.path = [ e for e in sys.path if e != appdir] 
        sys.path.insert(0,os.path.join(appdir, 'libs'))
        sys.path.insert(0,os.path.join(appdir, 'game_src'))
    except ValueError:
        print 'Please run from an OS console.'
        import time
        time.sleep(10)
        sys.exit(1)
adjust_to_correct_appdir()

# handle options
def get_options():
    import optparse
    parser = optparse.OptionParser()
    parser.add_option("-x", "--width", type='int', dest="width", default='800',
                      help="set window width", metavar="WIDTH")
    parser.add_option("-y", "--height", type="int", dest="height", default='600',
                      help="set window height", metavar="HEIGHT")
    parser.add_option("-F", "--fullscreen", dest="fullscreen", default=False,
                      help="set fullscreen mode on", action="store_true")
    parser.add_option("--startlevel", type='int', dest="startlevel", default='-1',
                      help="first level to play", metavar="STARTLEVEL")
    parser.add_option("--sound", dest="sound", default=True,
                      help="enables sound, default True", metavar="sound")
    (options, args) = parser.parse_args()
    members = ['width', 'height', 'fullscreen', 'startlevel', 'sound']
    d = {}
    for k in members:
        d[k] = getattr(options, k)
    return d

import gg
gg.session = get_options()
#print options

# todo get audio potential availability

import main
main.run_game()


